package com.example.security.provider.impl;

import com.example.security.domain.ShiroUserDetail;
import com.example.security.properties.CompanyProperties;
import com.example.security.provider.ShiroUserDetailService;
import com.example.security.provider.AbstractSocialUserProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: lex
 * @Date: 2019/2/1
 */
@Component
@Slf4j
public class AbstractSocialUserProviderImpl extends AbstractSocialUserProvider {

    @Autowired
    private CompanyProperties companyProperties;

    @Autowired
    private ShiroUserDetailService shiroUserDetailService;

    @Override
    public ShiroUserDetail getUserDetail(UsernamePasswordToken token) throws AuthenticationException {
        String itemId = token.getUsername().split(":"+ companyProperties.getLoginSplit()+":")[1];
        String socialProviderId = new String(token.getPassword());
        return shiroUserDetailService.getBySocialProvider(itemId, socialProviderId);
    }
}
